﻿using System;
using System.Collections.Generic;
using System.Text;
using SalePartial.IDAL;
using DataLayerAgent;
using System.Data.SqlClient;
using System.Data;
using SalePartial.Utility;
using SalePartial.Model;

namespace SalePartial.SQLServerDAL
{
    class XPUserProfile : IXPUserProfile
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int Delete(Guid UserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfileDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByUserID(Guid UserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesDeleteByUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPUserProfileInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("JobTitle", info.JobTitle),
			new SqlParameter("FamilyName", info.FamilyName),
			new SqlParameter("FirstName", info.FirstName),
			new SqlParameter("OfficePhone", info.OfficePhone),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Province", info.Province),
			new SqlParameter("City", info.City),
			new SqlParameter("PostCode", info.PostCode),
			new SqlParameter("Software", info.Software),
			new SqlParameter("UserCollection", info.UserCollection),
			new SqlParameter("IsApprovedVendor", info.IsApprovedVendor),
			new SqlParameter("IsApprovedBuyer", info.IsApprovedBuyer),
			new SqlParameter("NotificationEnabled", info.NotificationEnabled),
			new SqlParameter("NotificationCollection", info.NotificationCollection)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfileInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectAll]", parameters, "XPUserProfile_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            //SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            //return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectByUserID]", parameters, "XPUserProfile_ByUserID");

            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", "UserID='" + UserID+"'") };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectDynamic]", parameters, "xunpan_XPUserProfilesSelectDynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int SelectDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public  DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectDynamic]", parameters, "XPUserProfile_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public  DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectPaged]", parameters, "XPUserProfile_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReader(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfileSelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReaderByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            //SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            //return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectByUserID]", parameters);

            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", "UserID='" + UserID + "'") };
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfilesSelectDynamic]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectSingle(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPUserProfileSelect]", parameters, "XPUserProfile_Single");
            DataTable dt = ds.Tables["XPUserProfile_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPUserProfileInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("JobTitle", info.JobTitle),
			new SqlParameter("FamilyName", info.FamilyName),
			new SqlParameter("FirstName", info.FirstName),
			new SqlParameter("OfficePhone", info.OfficePhone),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Province", info.Province),
			new SqlParameter("City", info.City),
			new SqlParameter("PostCode", info.PostCode),
			new SqlParameter("Software", info.Software),
			new SqlParameter("UserCollection", info.UserCollection),
			new SqlParameter("IsApprovedVendor", info.IsApprovedVendor),
			new SqlParameter("IsApprovedBuyer", info.IsApprovedBuyer),
			new SqlParameter("NotificationEnabled", info.NotificationEnabled),
			new SqlParameter("NotificationCollection", info.NotificationCollection)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPUserProfileUpdate]", parameters, RowsAffected);
        }
    }
}
